package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcWdbh;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcWdbhMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcWdbhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车温度保护测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcWdbhServiceImpl implements IDataWgjlcWdbhService
{
    @Autowired
    private DataWgjlcWdbhMapper dataWgjlcWdbhMapper;

    /**
     * 查询无轨胶轮车温度保护测试项
     * 
     * @param wdbhId 无轨胶轮车温度保护测试项主键
     * @return 无轨胶轮车温度保护测试项
     */
    @Override
    public DataWgjlcWdbh selectDataWgjlcWdbhByWdbhId(Long wdbhId)
    {
        return dataWgjlcWdbhMapper.selectDataWgjlcWdbhByWdbhId(wdbhId);
    }

    /**
     * 查询无轨胶轮车温度保护测试项列表
     * 
     * @param dataWgjlcWdbh 无轨胶轮车温度保护测试项
     * @return 无轨胶轮车温度保护测试项
     */
    @Override
    public List<DataWgjlcWdbh> selectDataWgjlcWdbhList(DataWgjlcWdbh dataWgjlcWdbh)
    {
        return dataWgjlcWdbhMapper.selectDataWgjlcWdbhList(dataWgjlcWdbh);
    }

    /**
     * 新增无轨胶轮车温度保护测试项
     * 
     * @param dataWgjlcWdbh 无轨胶轮车温度保护测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcWdbh(DataWgjlcWdbh dataWgjlcWdbh)
    {
        dataWgjlcWdbh.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcWdbhMapper.insertDataWgjlcWdbh(dataWgjlcWdbh);
    }

    /**
     * 修改无轨胶轮车温度保护测试项
     * 
     * @param dataWgjlcWdbh 无轨胶轮车温度保护测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcWdbh(DataWgjlcWdbh dataWgjlcWdbh)
    {
        dataWgjlcWdbh.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcWdbh.getTestOneDataList().isEmpty()) {
            dataWgjlcWdbh.setDataList(JSON.toJSONString(dataWgjlcWdbh.getTestOneDataList()));
        }
        return dataWgjlcWdbhMapper.updateDataWgjlcWdbh(dataWgjlcWdbh);
    }

    /**
     * 查询无轨胶轮车-温度保护测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-温度保护测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcWdbh>> selectDataWgjlcWdbhByDataTaskId(Long dataTaskId) {
        List<DataWgjlcWdbh> dataWgjlcWdbhEntities = dataWgjlcWdbhMapper.selectDataWgjlcWdbhByDataTaskId(dataTaskId);
        if (dataWgjlcWdbhEntities.size() != 0) {
            dataWgjlcWdbhEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcWdbhEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcWdbhByDataTaskId(Long dataTaskId) {
        return dataWgjlcWdbhMapper.updateDataWgjlcWdbhByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-温度保护测试项
     *
     * @param dataWgjlcWdbh 无轨胶轮车-温度保护测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcWdbh(List<DataWgjlcWdbh> dataWgjlcWdbh) {
        return dataWgjlcWdbhMapper.batchDataWgjlcWdbh(dataWgjlcWdbh);
    }

    /**
     * 批量删除无轨胶轮车温度保护测试项
     * 
     * @param wdbhIds 需要删除的无轨胶轮车温度保护测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcWdbhByWdbhIds(Long[] wdbhIds)
    {
        return dataWgjlcWdbhMapper.deleteDataWgjlcWdbhByWdbhIds(wdbhIds);
    }

    /**
     * 删除无轨胶轮车温度保护测试项信息
     * 
     * @param wdbhId 无轨胶轮车温度保护测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcWdbhByWdbhId(Long wdbhId)
    {
        return dataWgjlcWdbhMapper.deleteDataWgjlcWdbhByWdbhId(wdbhId);
    }
}
